<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var zTreeObj;
// zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
var setting = {
		 /* async: {
	        enable: true,
	        url: '$!{webPath}/tssy/tsSyResource/loadTreeData',
	        contentType: "application/json",
	        type:"get",
	        autoParam: ["id"]
	    }  */
	    check: {  
            enable: true
        }
};

// zTree 的数据属性，深入使用请参考 API 文档（zTreeNode 节点数据详解）
function initTree(){
	 $.ajax({
         url: '$!{webPath}/tssy/tsSyRoleResource/loadTreeData',
         type: 'get',
         data: {"pid":"0","roleId":"$!{record.id}"},
         dataType: 'json',
         async:false,
         success: function(d){
        	 zTreeObj = $.fn.zTree.init($.CurrentDialog.find("#treeRoleResource"), setting, d);
        	 zTreeObj.expandAll(true); 
         }
     });
}

$(document).ready(function(){
	if("$!{record.id}"!=undefined&&"$!{record.id}"!=""){
		initTree();
	}
});
  
</script>
<div class="bjui-pageContent">
	<!-- 查询和编辑公用一个页面，id空：新增，id不空：编辑--
		注意：本系统遵循restful架构，action处理时method严格按照 新增：post 编辑：put 删除:delete 查询：get(默认)
		由于删除和编辑form表单不支持，所以必须在action的url后面增加参数_method=put或_method=delete
	-->
	#if(!$!{record.id})
	<form id="roleForm" type="post" action="$!{webPath}/tssy/tsSyRole/add?navTabId=tsSyRoleLiNav&closeCurrent=true"  data-toggle="validate" data-alertmsg="false">
	#else
    <form id="roleForm" type="post" action="$!{webPath}/tssy/tsSyRole/update?_method=put&navTabId=tsSyRoleLiNav&closeCurrent=true" data-toggle="validate" data-alertmsg="false">
	#end
        #if(!$!{record.id})
		<input type="hidden" name="id" value="" />
		#else
		<input type="hidden" name="id" value="$!{record.id}"/>
		<input type="hidden" id="resourceIds" name="resourceIds" value="">
		#end
        <table class="table table-condensed table-hover" width="100%"> 
            <tbody>
            	<tr>
            		
            	</tr>
            	<tr>
				<td>
					<label for="j-roleName" class="control-label x85">角色名称：</label>
					
					<input data-rule="required" maxlength=50 type="text" name="roleName"  value="$!record.roleName" size="15" id="j-roleName"/>
				</td>
            	
				<td>
					<label for="j-remark" class="control-label x85">角色描述：</label>
					
					<input type="text" name="remark"  value="$!record.remark" size="15" id="j-remark"/>
				</td>
            	
            	</tr>
            	 #if($!{record.id})
            	<tr>
            	<td>
            	<ul style="float:left;"><label for="j-remark" class="control-label x85">资源：</label></ul><ul style="float:left;" id="treeRoleResource" class="ztree"></ul></td>
            	<td></td>
            	</tr>
            	#end
            </tbody>
        </table>
    </form>
</div>
<div class="bjui-pageFooter">
    <ul>
        <li><button type="button" class="btn-close" data-icon="close">取消</button></li>
        <li><button type="button" class="btn-default" data-icon="save" onclick="saveRole()">保存</button></li>
    </ul>
</div>
<script type="text/javascript">
function saveRole(){
	if("$!{record.id}"){
		setRoleResource();
	}
	$("#roleForm").submit();
}
function setRoleResource(){
	var nodes = zTreeObj.getCheckedNodes(true);
	var checkNodes = "";
	$.each(nodes,function(key,value){
		if(key==0){
			checkNodes = value.id;
		}else{
			checkNodes = checkNodes +","+value.id;
		}
	});
	$("#resourceIds").val(checkNodes);
}
</script>